package com.example.hyw.szysteam.presenter;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.model.ClassModel;
import com.example.hyw.szysteam.view.JoinClassDialog;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by HYW on 2018/6/8.
 */

public class JoinClassPresenter {
    ClassModel classModel=new ClassModel();
    JoinClassDialog joinClassDialog;

    public JoinClassPresenter(JoinClassDialog joinClassDialog) {
        this.joinClassDialog = joinClassDialog;
    }

    public void joinClass(String email,String classid){
        classModel.joinclass(email,classid)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<String>>() {
                    @Override
                    public void accept(HttpResult<String> stringHttpResult) throws Exception {
                        int i=stringHttpResult.getResult();
                        if(i==0){
                            joinClassDialog.joinSuccess();
                        }else {
                            joinClassDialog.joinFail(i);
                        }
                    }
                });
    }

}
